/*
ID:luongho3
LANG:C++
TASK:prefix
*/
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("prefix.in");
ofstream fout("prefix.out");
#define MAXP 205
#define MAXL 200005
string primitives[MAXP], data,temp;
int nprim,dlen,start[MAXL];
bool matchat(string s, int pos) {
     int i,j;
     j=0;
     for (i=0;i<s.length();++i) {
         if (pos+j <  data.length()) {
            if (s[i] != data[pos+j]) {
               return false;
            }
            ++j;
         }
         else return false;
     }
     return true;
}
int main() {
    nprim = 0;
    do {
       fin >> temp;
       if (temp != ".") {
          nprim++;
          primitives[nprim] = temp;
       }
       else break;
    } while (true);
    data = "";
    while (fin >> temp) {
          data = data + temp;
    }
    dlen = data.length();
    int i,j,mval,plen;
    mval = -1;
    start[0]=1;
    for (i=0;i<dlen;++i) {
        if (start[i]==1) {
           for (j=1;j<=nprim;++j) {
               if (matchat(primitives[j],i)) {
                  plen = primitives[j].length();
                  start[i+plen] = 1;
                  if (i+plen > mval) {
                     mval = i+primitives[j].length()-1;
                  }
               }
           }
        }
    }
    fout << mval+1 << "\n";
    return 0;
}
